#ifndef __TOYM__NET__ACCEPTER_H__
#define __TOYM__NET__ACCEPTER_H__

#include "net/Socket.h"
#include "net/Callables.h"
#include "net/Channel.h"
#include "net/InetAddress.h"
#include "Base/noncopyable.h"

namespace toym
{
namespace net
{

class EventLoop;

class Acceptor: noncopyable {
public:
    Acceptor(EventLoop* loop, const InetAddress& addr);

    void setNewConnectionCallback(const NewConnectionCallback_t& cb) {
        m_newConnectionCb = cb;
    }
    void setNewConnectionCallback(NewConnectionCallback_t&& cb) {
        m_newConnectionCb = std::move(cb);
    }
    void listen();
private:

    void handleRead();
    void handleError();

    EventLoop* m_loop;
    Socket m_acceptSocket;
    Channel m_channel;
    NewConnectionCallback_t m_newConnectionCb;
};

} // namespace net

} // namespace toym


#endif //__TOYM__NET__ACCEPTER_H__